package com.yyq.adms.hngg.action;

import java.io.File;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.yyq.adms.hngg.bpo.MagazineDetailBpo;
import com.yyq.adms.hngg.pojo.MagazineDetail;
import com.yyq.adms.hngg.pojo.PeriodicalMagazine;
import com.yyq.adms.sysmanage.pojo.Accessory;
import com.yyq.adms.util.JxlsUtil;
import com.yyq.adms.util.JxlsVo;
import com.yyq.adms.util.ValidateUtil;
import com.yyq.adms.util.ValidateVo;
import com.yyq.sos.action.BaseAction;
import com.yyq.sos.constants.ActionType;
import com.yyq.sos.constants.Constants;
import com.yyq.sos.permission.LoginUser;
import com.yyq.sos.util.PermissionsUtil;
import com.yyq.sos.util.SysParametersUtil;

/**
 * 华南港工详情ACTION
 * 
 * @author 杨应滨
 * @2012-12-17
 * 
 */
@Controller("MagazineDetailAction")
@Scope("prototype")
public class MagazineDetailAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private MagazineDetail po = new MagazineDetail();

	private MagazineDetailBpo bpo;

	private String parent;
	
	private String magazineName;
	
	private List accessoryList;
	
	private String currentPageNo;

	public String getCurrentPageNo() {
		return currentPageNo;
	}

	public void setCurrentPageNo(String currentPageNo) {
		this.currentPageNo = currentPageNo;
	}

	public String getMagazineName() {
		return magazineName;
	}

	public void setMagazineName(String magazineName) {
		this.magazineName = magazineName;
		try {
			this.magazineName = URLDecoder.decode(this.magazineName, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

	public List getAccessoryList() {
		return accessoryList;
	}

	public void setAccessoryList(List accessoryList) {
		this.accessoryList = accessoryList;
	}

	public MagazineDetail getPo() {
		return po;
	}

	public void setPo(MagazineDetail po) {
		this.po = po;
	}

	public MagazineDetailBpo getBpo() {
		return bpo;
	}

	@Resource(name = "MagazineDetailBpo")
	public void setBpo(MagazineDetailBpo bpo) {
		bpo.setCls(po.getClass());
		this.bpo = bpo;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	@Override
	public String execute() throws Exception {
		super.setObj(po);
		super.setBpo(bpo);
		String ret = super.execute();
		po = (MagazineDetail) getObj();
		return ret;
	}

	@Override
	public String data() {
		LoginUser user = (LoginUser) this.getSession().getAttribute(
				Constants.LOGIN_USER);
		String moduleName = getModuleName(this.getRequest().getRequestURI());
		boolean isPerm = PermissionsUtil.checkPermissionByCode(this
				.getSession(), moduleName, Constants.RIGHT_GLOBAL);
		this.getSession().setAttribute("periodicalPageNo", currentPageNo);

		String hql = "";
		
		hql = "from MagazineDetail where belongParentID = "
			+ Integer.valueOf(parent);
		this.setFormData(bpo.searchPage(hql, getPageForm().getPageNo(),
				getPageForm().getPageSize()));
		
		hql = "from Accessory where sourceRecordId = "+parent +" and yyqTableName='periodicalmagazine'";
		accessoryList = bpo.search(hql);
		return ActionType.ACTION_DATA_LIST;
	}

	@Override
	public String delete() {

		boolean result = bpo
				.execSql("delete from periodicalmagazinedetail where belongParentID = "
						+ Integer.valueOf(parent));
		if (result) {
			setMsg("{processId:\"1\",msg:\"清除论文信息成功\"}");
		} else {
			setMsg("{processId:\"-1\",msg:\"清除论文信息失败\"}");
		}
		return ActionType.ACTION_MSG;
	}


}
